using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using NUnit.Framework;

namespace DatabaseUnitTesting.Utilities.StoredProcedure.Tests
{
    [TestFixture]
    public class SqlGeneratorTests
    {
        [Test] 
        public void GenerateScript()
        {
            string connectionString =
                "Application Name=UnitTests;Trusted_Connection=true;Server=(local);Database=astyler";
            
            SqlConnection connection = new SqlConnection(connectionString);
            connection.Open();

            SqlCommand storedProcedure = new SqlCommand("TwoResultSets", connection);
            storedProcedure.CommandType = CommandType.StoredProcedure;

            List<string> commands =
                SqlGenerator.GenerateScript(ResultSetParser.Parse(storedProcedure), "dbo", "someTable");

            string[] expected = new string[2];
            
            expected[0] =
                "--Dropping Existing Table dbo.someTable0\n IF OBJECT_ID('dbo.someTable0') IS NOT NULL DROP TABLE dbo.someTable0";

            expected[1] =
                "--Creating Table dbo.someTable0\n CREATE TABLE dbo.someTable0 (id int,c varchar(100),price decimal(18,0) )";

            Assert.AreEqual(expected[0], commands[0]);
            Assert.AreEqual(expected[1], commands[1]);

            Assert.IsTrue(commands[2].Contains("INSERT"));
        }
    }
}